package com;

import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;

import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.MethodSorters;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.boot.test.WebIntegrationTest;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import com.App;
import com.PiwikDao;

@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes =App.class)
@WebIntegrationTest(randomPort = true)
@DirtiesContext
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class DaoDemo {
	@Autowired
	PiwikDao logdao;
	
	@Test
	public void testQuery() throws ParseException{
		
		logdao.queryPiwikTime(0)
		.forEach(data->{
			data.forEach((key,value)->{
				System.out.println(key+" : "+value+" : "+value.getClass().getName());
				if (key.equals("server_time")) {
					java.sql.Timestamp time = (Timestamp) value;
					System.out.println(time.getTime());
					
				}
			});
		});	
		
		 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		 System.out.println(sdf.parse("2016-10-20 09:58:56").getTime());
		 
		 
//		Map<String, Object> piwikTime = Maps.newHashMap();
//		piwikTime.put("idlink_va", 5430L);		
//		piwikTime.put("server_time",new Timestamp(sdf.parse("2016-10-20 09:58:56").getTime()));
//		piwikTime.put("custom_var_v4", "1476957627862");
//		
//		
//		System.err.println(piwikTime);
	}
}
